home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / mus / play / tracker_4_31.lzh / tracker / display.c < prev    next >
C/C++ Source or Header  |  1995-05-11  |  14KB  |  709 lines

  1. /* display.c 
  2.     vi:ts=3 sw=3:
  3.  */
  4.  
  5. /* $Id: display.c,v 4.21 1995/05/11 12:24:57 espie Exp espie $
  6.  * $Log: display.c,v $
  7.  * Revision 4.21  1995/05/11  12:24:57  espie
  8.  * DELAY +1.
  9.  *
  10.  * Revision 4.20  1995/03/11  21:40:38  espie
  11.  * Added jump_pattern, invert_loop.
  12.  *
  13.  * Revision 4.19  1995/03/04  00:16:00  espie
  14.  * Implemented vibrato control.
  15.  *
  16.  * Revision 4.18  1995/03/03  14:23:41  espie
  17.  * Color fixed (mostly).
  18.  *
  19.  * Revision 4.17  1995/02/27  14:24:23  espie
  20.  * Minor bug in dump_delimiter.
  21.  *
  22.  * Revision 4.16  1995/02/25  15:43:11  espie
  23.  * Display MUCH better.
  24.  *
  25.  * Revision 4.15  1995/02/24  15:36:39  espie
  26.  * Stupid bug: missing sample name in table (8)
  27.  *
  28.  * Revision 4.14  1995/02/21  21:13:16  espie
  29.  * Cleaned up source. Moved minor pieces of code around.
  30.  *
  31.  * Revision 4.13  1995/02/21  17:54:32  espie
  32.  * Internal problem: buggy RCS. Fixed logs.
  33.  *
  34.  * Revision 4.11  1995/02/20  22:28:50  espie
  35.  * tremolo.
  36.  *
  37.  * Revision 4.10  1995/02/20  16:49:58  espie
  38.  * Bug: need to check sample length against 0 before dividing.
  39.  *
  40.  * Revision 4.9  1995/02/14  04:02:28  espie
  41.  * Kludge for the amiga.
  42.  *
  43.  * Revision 4.7  1995/02/06  14:50:47  espie
  44.  * Changed sample_info.
  45.  *
  46.  * Revision 4.6  1995/02/01  20:41:45  espie
  47.  * Added color.
  48.  *
  49.  * Revision 4.5  1995/02/01  16:39:04  espie
  50.  * Includes moved to defs.h
  51.  *
  52.  * Revision 4.0  1994/01/11  17:45:22  espie
  53.  * Major change: does not use sprintf heavily.
  54.  *
  55.  * Generalized open.c.
  56.  * Use name_of_note(), no need for run_in_fg().
  57.  * Small bug: strcpy -> stringcopy.
  58.  * Cond code to make show/not show robust.
  59.  * Added instrument name as shown per display.c.
  60.  * Major change: use scroller interface.
  61.  * Lots of LOCAL added + minor changes.
  62.  * Try to get rid of %d format in printf.
  63.  */
  64.      
  65. #include "defs.h"
  66. #include "song.h"
  67. #include "channel.h"
  68. #include "extern.h"
  69. #include "tags.h"
  70. #include "prefs.h"
  71.  
  72. ID("$Id: display.c,v 4.21 1995/05/11 12:24:57 espie Exp espie $")
  73. LOCAL void init_display P((void));
  74. LOCAL void (*INIT)P((void)) = init_display;
  75.      
  76. #define ENTRY_SIZE 14
  77. LOCAL char *base;
  78.  
  79. /* lookup tables for speed */
  80. LOCAL char *num[] = {
  81. " 0", " 1", " 2", " 3", " 4", " 5", " 6", " 7", " 8", " 9",
  82. "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
  83. "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
  84. "30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
  85. "40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
  86. "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
  87. "60", "61", "62", "63", "64", "65", "66", "67", "68", "69",
  88. "70", "71", "72", "73", "74", "75", "76", "77", "78", "79",
  89. "80", "81", "82", "83", "84", "85", "86", "87", "88", "89",
  90. "90", "91", "92", "93", "94", "95", "96", "97", "98", "99",
  91. "00", "01", "02", "03", "04", "05", "06", "07", "08", "09"};
  92.  
  93. char instname[] = { ' ', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  94. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  95. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
  96.  
  97. LOCAL void reset_buffer()
  98.    {
  99.    base = new_scroll();
  100.    }
  101.  
  102. LOCAL void next_entry()
  103.    {
  104.     if (get_pref_scalar(PREF_COLOR))
  105.         base += 7;
  106.    base += ENTRY_SIZE;
  107.    }
  108.  
  109. /* utility functions to avoid the overhead of strncpy */
  110. LOCAL void copy1(to, from)
  111. char *to, *from;
  112.    {
  113.    *to = *from;
  114.    }
  115.    
  116. LOCAL void copy2(to, from)
  117. char *to, *from;
  118.    {
  119.    *to++ = *from++;
  120.    *to = *from;
  121.    }
  122.  
  123. LOCAL void copy3(to, from)
  124. char *to, *from;
  125.    {
  126.    *to++ = *from++;
  127.    *to++ = *from++;
  128.    *to = *from;
  129.    }
  130.  
  131. LOCAL void copy4(to, from)
  132. char *to, *from;
  133.     {
  134.    *to++ = *from++;
  135.    *to++ = *from++;
  136.    *to++ = *from++;
  137.    *to = *from;
  138.     }
  139.  
  140. LOCAL void stringcopy(to, from)
  141. char *to, *from;
  142.    {
  143.    while (*from)
  144.       *to++ = *from++;
  145.    }
  146.  
  147. LOCAL void num2(to, n)
  148. char *to;
  149. int n;
  150.    {
  151.    char *v = num[n];
  152.    *to++ = *v++;
  153.    *to = *v;
  154.    }
  155.  
  156. LOCAL void num3(to, n)
  157. char *to;
  158. int n;
  159.    {
  160.    char *v;
  161.  
  162.    if (n >= 100)
  163.       *to = "0123456789"[n/100];
  164.    while (n > 109)
  165.       n -= 100;
  166.    v = num[n];
  167.    to++;
  168.    *to++ = *v++;
  169.    *to = *v;
  170.    }
  171.  
  172. LOCAL void (*table[NUMBER_EFFECTS]) P((int samp, int para, int note, \
  173.     struct channel *ch));
  174.  
  175. /* all the various dump for the effects */
  176. LOCAL void disp_default(samp, para, note, ch)
  177. int samp, para, note;
  178. struct channel *ch;
  179.    {
  180.     if (ch->samp->start)
  181.         copy3(base+2, name_of_note(note));
  182.    }
  183.  
  184. LOCAL void disp_speed(samp, para, note, ch)
  185. int samp, para, note;
  186. struct channel *ch;
  187.    {
  188.     if (ch->samp->start)
  189.         copy3(base+2, name_of_note(note));
  190.    if (para < 32)
  191.       {
  192.       stringcopy(base+6, "SPD");
  193.       num2(base+10, para);
  194.       }
  195.    else
  196.       {
  197.       stringcopy(base+6, "spd%");
  198.       num3(base+10, para * 100/NORMAL_FINESPEED);
  199.       }
  200.    }
  201.  
  202. LOCAL void disp_nothing(samp, para, note, ch)
  203. int samp, para, note;
  204. struct channel *ch;
  205.    {
  206.    }
  207.  
  208. LOCAL void disp_portamento(samp, para, note, ch)
  209. int samp, para, note;
  210. struct channel *ch;
  211.    {
  212.     if (ch->samp->start)
  213.         {
  214.         stringcopy(base+2, "-->");
  215.         copy3(base+5, name_of_note(note));
  216.         if (para)
  217.             {
  218.             base[8] = '(';
  219.             num3(base+9, para);
  220.             base[12] = ')';
  221.             }
  222.         }
  223.    }
  224.  
  225. LOCAL void disp_portaslide(samp, para, note, ch)
  226. int samp, para, note;
  227. struct channel *ch;
  228.    {
  229.     if (ch->samp->start)
  230.         {
  231.         stringcopy(base+2, "-->");
  232.         copy3(base+5, name_of_note(note));
  233.         if (LOW(para))
  234.             {
  235.             base[9] = '-';
  236.             num2(base+10, LOW(para));
  237.             }
  238.         else
  239.             {
  240.             base[9] = '+';
  241.             num2(base+10, HI(para));
  242.             }
  243.         }
  244.    }
  245.  
  246. LOCAL void disp_upslide(samp, para, note, ch)
  247. int samp, para, note;
  248. struct channel *ch;
  249.    {
  250.     if (ch->samp->start)
  251.         {
  252.         copy3(base+2, name_of_note(note));
  253.         base[8] = '-';
  254.         if (para)
  255.             num3(base+9, para);
  256.         }
  257.    }
  258.  
  259. LOCAL void disp_downslide(samp, para, note, ch)
  260. int samp, para, note;
  261. struct channel *ch;
  262.    {
  263.     if (ch->samp->start)
  264.         {
  265.         copy3(base+2, name_of_note(note));
  266.         base[8] = '+';
  267.         if (para)
  268.             num3(base+9, para);
  269.         }
  270.    }
  271.  
  272. LOCAL void disp_vibrato(samp, para, note, ch)
  273. int samp, para, note;
  274. struct channel *ch;
  275.    {
  276.     if (ch->samp->start)
  277.         copy3(base+2, name_of_note(note));
  278.     if (para || ch->samp->start)
  279.         copy2(base+6, "vb");
  280.    if (para)
  281.       {
  282.       num2(base+8, LOW(para));
  283.       base[10] = '/';
  284.       num2(base+11, HI(para));
  285.       }
  286.    }
  287.  
  288. LOCAL void disp_vibrato_wave(samp, para, note, ch)
  289. int samp, para, note;
  290. struct channel *ch;
  291.     {
  292.     if (ch->samp->start)
  293.         copy3(base+2, name_of_note(note));
  294.     copy2(base+6, "vb");
  295.     switch(para)
  296.         {
  297.     case 0:
  298.         copy4(base+9, "sine");
  299.         break;
  300.     case 1:
  301.         copy4(base+9, "sqre");
  302.         break;
  303.     case 2:
  304.         copy4(base+9, "ramp");
  305.         break;
  306.     case 4:
  307.         copy4(base+9, "SINE");
  308.         break;
  309.     case 5:
  310.         copy4(base+9, "SQRE");
  311.         break;
  312.     case 6:
  313.         copy4(base+9, "RAMP");
  314.         break;
  315.     default:
  316.         copy4(base+9, "????");
  317.         }
  318.     }
  319.  
  320. LOCAL void disp_tremolo_wave(samp, para, note, ch)
  321. int samp, para, note;
  322. struct channel *ch;
  323.     {
  324.     if (ch->samp->start)
  325.         copy3(base+2, name_of_note(note));
  326.     copy2(base+6, "tr");
  327.     switch(para)
  328.         {
  329.     case 0:
  330.         copy4(base+9, "sine");
  331.         break;
  332.     case 1:
  333.         copy4(base+9, "sqre");
  334.         break;
  335.     case 2:
  336.         copy4(base+9, "ramp");
  337.         break;
  338.     case 4:
  339.         copy4(base+9, "SINE");
  340.         break;
  341.     case 5:
  342.         copy4(base+9, "SQRE");
  343.         break;
  344.     case 6:
  345.         copy4(base+9, "RAMP");
  346.         break;
  347.     default:
  348.         copy4(base+9, "????");
  349.         }
  350.     }
  351.  
  352. LOCAL void disp_tremolo(samp, para, note, ch)
  353. int samp, para, note;
  354. struct channel *ch;
  355.    {
  356.     if (ch->samp->start)
  357.         copy3(base+2, name_of_note(note));
  358.     if (para || ch->samp->start)
  359.         copy2(base+6, "tr");
  360.    if (para)
  361.       {
  362.       num2(base+8, LOW(para));
  363.       base[10] = '/';
  364.       num2(base+11, HI(para));
  365.       }
  366.    }
  367.  
  368. LOCAL void disp_vibratoslide(samp, para, note, ch)
  369. int samp, para, note;
  370. struct channel *ch;
  371.    {
  372.     if (ch->samp->start)
  373.         {
  374.         copy3(base+2, name_of_note(note));
  375.         stringcopy(base+6, "vibs");
  376.         if (LOW(para))
  377.             {
  378.             base[10] = '-';
  379.             num2(base+11, LOW(para));
  380.             }
  381.         else
  382.             {
  383.             base[10] = '+';
  384.             num2(base+11, HI(para));
  385.             }
  386.         }
  387.    }
  388.  
  389. LOCAL void disp_slidevol(samp, para, note, ch)
  390. int samp, para, note;
  391. struct channel *ch;
  392.    {
  393.     if (ch->samp->start)
  394.         {
  395.         copy3(base+2, name_of_note(note));
  396.         stringcopy(base+6, "vol");
  397.         if (LOW(para))
  398.             {
  399.             base[10] = '-';
  400.             num2(base+11, LOW(para));
  401.             }
  402.         else
  403.             if (HI(para))
  404.                 {
  405.                 base[10] = '+';
  406.                 num2(base+11, HI(para));
  407.                 }
  408.         }
  409.    }
  410.  
  411. LOCAL void disp_volume(samp, para, note, ch)
  412. int samp, para, note;
  413. struct channel *ch;
  414.    {
  415.     if (ch->samp->start)
  416.         {
  417.         copy3(base+2, name_of_note(note));
  418.         if (para)
  419.             {
  420.             stringcopy(base+6, "vol");
  421.             num3(base+10, para);
  422.             }
  423.         else
  424.             stringcopy(base+6, "silent");
  425.         }
  426.    }
  427.  
  428. LOCAL void disp_arpeggio(samp, para, note, ch)
  429. int samp, para, note;
  430. struct channel *ch;
  431.    {
  432.     if (ch->samp->start)
  433.         {
  434.         if (note != NO_NOTE)
  435.             {
  436.             copy3(base+2, name_of_note(note));
  437.             copy3(base+6, name_of_note(note + LOW(para)));
  438.             copy3(base+10, name_of_note(note + HI(para)));
  439.             }
  440.         else
  441.             if (ch->note == NO_NOTE)
  442.                 stringcopy(base, "Arp error");
  443.             else
  444.                 {
  445.                 copy3(base+6, name_of_note(ch->note + LOW(para)));
  446.                 copy3(base+10, name_of_note(ch->note + HI(para)));
  447.                 }  
  448.         }
  449.    }
  450.  
  451. LOCAL void disp_retrig(samp, para, note, ch)
  452. int samp, para, note;
  453. struct channel *ch;
  454.    {
  455.     if (ch->samp->start)
  456.         {
  457.         copy3(base+2, name_of_note(note));
  458.         stringcopy(base + 6, "rtg");
  459.         num3(base+9, para);
  460.         }
  461.    }
  462.  
  463.  
  464. LOCAL void disp_note_cut(samp, para, note, ch)
  465. int samp, para, note;
  466. struct channel *ch;
  467.    {
  468.     if (ch->samp->start)
  469.         {
  470.         copy3(base+2, name_of_note(note));
  471.         stringcopy(base+6, "cut");
  472.         num3(base+9, para);
  473.         }
  474.    }
  475.  
  476. LOCAL void disp_late_start(samp, para, note, ch)
  477. int samp, para, note;
  478. struct channel *ch;
  479.    {
  480.     if (ch->samp->start)
  481.         {
  482.         copy3(base+2, name_of_note(note));
  483.         stringcopy(base+6, "lte");
  484.         num3(base+9, para);
  485.         }
  486.    }
  487.  
  488. LOCAL void disp_offset(samp, para, note, ch)
  489. int samp, para, note;
  490. struct channel *ch;
  491.    {
  492.     if (ch->samp->start)
  493.         {
  494.         copy3(base+2, name_of_note(note));
  495.         stringcopy(base+6, "off   %");
  496.         if (ch->samp->length)
  497.             num3(base+9, para * 25600/ch->samp->length);
  498.         }
  499.    }
  500.  
  501. LOCAL void disp_smooth_up(samp, para, note, ch)
  502. int samp, para, note;
  503. struct channel *ch;
  504.    {
  505.     if (ch->samp->start)
  506.         {
  507.         copy3(base+2, name_of_note(note));
  508.         stringcopy(base+6, "sth-");
  509.         num3(base+10, para);
  510.         }
  511.    }
  512.  
  513. LOCAL void disp_smooth_down(samp, para, note, ch)
  514. int samp, para, note;
  515. struct channel *ch;
  516.    {
  517.     if (ch->samp->start)
  518.         {
  519.         copy3(base+2, name_of_note(note));
  520.         stringcopy(base+6, "sth+");
  521.         num3(base+10, para);
  522.         }
  523.    }
  524.  
  525. LOCAL void disp_smooth_upvolume(samp, para, note, ch)
  526. int samp, para, note;
  527. struct channel *ch;
  528.    {
  529.     if (ch->samp->start)
  530.         {
  531.         copy3(base+2, name_of_note(note));
  532.         stringcopy(base+8, "++");
  533.         num3(base+10, para);
  534.         }
  535.    }
  536.  
  537. LOCAL void disp_smooth_downvolume(samp, para, note, ch)
  538. int samp, para, note;
  539. struct channel *ch;
  540.    {
  541.     if (ch->samp->start)
  542.         {
  543.         copy3(base+2, name_of_note(note));
  544.         stringcopy(base+8, "--");
  545.         num3(base+10, para);
  546.         }
  547.    }
  548.  
  549. LOCAL void disp_change_finetune(samp, para, note, ch)
  550. int samp, para, note;
  551. struct channel *ch;
  552.    {
  553.     if (ch->samp->start)
  554.         {
  555.         copy3(base+2, name_of_note(note));
  556.         stringcopy(base+6, "fine");
  557.         num2(base+11, para);
  558.         }
  559.    }
  560.  
  561. LOCAL void disp_skip(samp, para, note, ch)
  562. int samp, para, note;
  563. struct channel *ch;
  564.    {
  565.     if (ch->samp->start)
  566.         copy3(base+2, name_of_note(note));
  567.    if (para)
  568.       {
  569.       stringcopy(base+6, "skp");
  570.       num3(base+10, para);
  571.       }
  572.    else
  573.       stringcopy(base+6, "next");
  574.    }
  575.  
  576. LOCAL void disp_fastskip(samp, para, note, ch)
  577. int samp, para, note;
  578. struct channel *ch;
  579.    {
  580.     if (ch->samp->start)
  581.         copy3(base+2, name_of_note(note));
  582.    stringcopy(base+6, "ff");
  583.    num3(base+10, para);
  584.    }
  585.  
  586. LOCAL void disp_loop(samp, para, note, ch)
  587. int samp, para, note;
  588. struct channel *ch;
  589.    {
  590.     if (ch->samp->start)
  591.         copy3(base+2, name_of_note(note));
  592.    if (para == 0)
  593.       stringcopy(base+6, "SETLOOP");
  594.    else
  595.       {
  596.       stringcopy(base+6, "LOOP");
  597.       num3(base+10, para+1);
  598.       }
  599.    }
  600.  
  601. LOCAL void disp_delay_pattern(samp, para, note, ch)
  602. int samp, para, note;
  603. struct channel *ch;
  604.    {
  605.     if (ch->samp->start)
  606.         copy3(base+2, name_of_note(note));
  607.    stringcopy(base+6, "DLAY");
  608.    num3(base+10, para);
  609.    }
  610.  
  611. LOCAL void disp_gliss_ctrl(samp, para, note, ch)
  612. int samp, para, note;
  613. struct channel *ch;
  614.     {
  615.     if (ch->samp->start)
  616.         copy3(base+2, name_of_note(note));
  617.     if (para)
  618.         stringcopy(base+6, "gls on");
  619.     else
  620.         stringcopy(base+6, "gls off");
  621.     }
  622.  
  623. LOCAL void disp_invert_loop(samp, para, note, ch)
  624. int samp, para, note;
  625. struct channel *ch;
  626.     {
  627.     if (ch->samp->start)
  628.         copy3(base+2, name_of_note(note));
  629.     if (para)
  630.         {
  631.       stringcopy(base+6, "inv");
  632.       num3(base+10, para);
  633.         }
  634.     else
  635.         stringcopy(base+6, "inv off");
  636.     }
  637.  
  638. #define disp_nothing disp_default
  639.  
  640. LOCAL void init_display()
  641.    {
  642.    int i;
  643.  
  644.    for (i = 0; i < NUMBER_EFFECTS; i++)
  645.       table[i] = disp_nothing;
  646.     table[EFF_VIBRATO_WAVE] = disp_vibrato_wave;
  647.     table[EFF_TREMOLO_WAVE] = disp_tremolo_wave;
  648.     table[EFF_GLISS_CTRL] = disp_gliss_ctrl;
  649.    table[EFF_ARPEGGIO] = disp_arpeggio;
  650.    table[EFF_SPEED] = disp_speed;
  651.    table[EFF_SKIP] = disp_skip;
  652.    table[EFF_FF] = disp_fastskip;
  653.    table[EFF_VOLUME] = disp_volume;
  654.    table[EFF_VOLSLIDE] = disp_slidevol;
  655.    table[EFF_OFFSET] = disp_offset;
  656.    table[EFF_PORTA] = disp_portamento;
  657.    table[EFF_PORTASLIDE] = disp_portaslide;
  658.    table[EFF_UP] = disp_upslide;
  659.    table[EFF_DOWN] = disp_downslide;
  660.    table[EFF_VIBRATO] = disp_vibrato;
  661.     table[EFF_TREMOLO] = disp_tremolo;
  662.    table[EFF_VIBSLIDE] = disp_vibratoslide;
  663.    table[EFF_SMOOTH_UP] = disp_smooth_up;
  664.    table[EFF_SMOOTH_DOWN] = disp_smooth_down;
  665.    table[EFF_CHG_FTUNE] = disp_change_finetune;
  666.    table[EFF_LOOP] = disp_loop;
  667.    table[EFF_RETRIG] = disp_retrig;
  668.    table[EFF_S_UPVOL] = disp_smooth_upvolume;
  669.    table[EFF_S_DOWNVOL] = disp_smooth_downvolume;
  670.    table[EFF_NOTECUT] = disp_note_cut;
  671.    table[EFF_LATESTART] = disp_late_start;
  672.    table[EFF_DELAY] = disp_delay_pattern;
  673.     table[EFF_INVERT_LOOP] = disp_invert_loop;
  674.    reset_buffer();
  675.    }
  676.  
  677. void dump_event(ch, e)
  678. struct channel *ch;
  679. struct event *e;
  680.    {
  681.    INIT_ONCE;
  682.    
  683.     if (ch && base)    /* do we have a scroll line AND are we not finished */
  684.         {
  685.         if (get_pref_scalar(PREF_COLOR))
  686.             base = write_color(base, ch->samp->color);
  687.         if (ch->samp != empty_sample())
  688.             *base = instname[e->sample_number];
  689.         (*table[e->effect])(e->sample_number, e->parameters, e->note, ch);
  690.         next_entry();
  691.         }
  692.     else
  693.         {
  694.         scroll();
  695.         reset_buffer();
  696.         }
  697.     }
  698.  
  699. void dump_delimiter()
  700.     {
  701.     INIT_ONCE;
  702.     if (base)
  703. #ifdef AMIGA
  704.         *base++;
  705. #else
  706.         *base++= '|';
  707. #endif
  708.     }
  709.